//
//  MyViewController.m
//  test
//
//  Created by apple on 16/3/25.
//  Copyright © 2016年 ibendi. All rights reserved.
//
#import <AVFoundation/AVFoundation.h>


#import "MyViewController.h"
#import "ZYPinYinSearch.h"

#import "ZYChoiceView.h"
#import "ZYTableView.h"
#import "AESCrypt.h"
#import "UniversalEngine.h"
#import <CommonCrypto/CommonCryptor.h>
#import "ZYMainViewController.h"
#import "ZYDateilViewController.h"

@interface MyViewController ()

@property (nonatomic, strong) AVSpeechSynthesizer *synthesizer;

@end

@implementation MyViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =  [UIColor whiteColor];
    
//    self.navigationController.hidesBarsOnSwipe = YES;
    
//    MyDatailViewController *myDatail = [[MyDatailViewController alloc] init];
//    [self.navigationController pushViewController:myDatail animated:YES];
//    NSDictionary * dic  = @{@"page":@"2",@"time":@"1418816972",@"key":@"414953412a51f8fdcc0e0f2e5ac2fc03",@"sort":@"asc",@"pagesize":@"10"};
//    [[IBDNetworking sharedManager] GET:@"http://japi.juhe.cn/joke/content/list.from" parameters:dic success:^(id data) {
////        NSLog(@"----%@",data);
//    }];
    
    self.title = @"the me";
    
    __weak typeof(self) weekSelf = self ;
    [self setNavcRightItem:[UIImage imageNamed:@"icon-address list-press"] andSelectorBlock:^{
//        [self goLogInView];
        [weekSelf showListView];
        
    }];
    
    NSMutableDictionary *selsceDic = [NSMutableDictionary dictionary];
    NSArray *dataArray = @[@"澳门风云",@"澳门风云2",@"钢铁侠",@"美国队长"];
    
    ZYTableView *rootView = [[ZYTableView alloc] initWithFrame:CGRectMake(0, self.view_startY, self.view.width, self.view.height)];
    [self.view addSubview:rootView];

    [rootView zyCellForRowAtIndexPath:^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
        static NSString *cellString = @"newCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString];
        }
        
        cell.textLabel.text = dataArray[indexPath.row];
        if ([[selsceDic valueForKey:@"APP_CHANGEVOICE" ]isEqualToString: dataArray[indexPath.row]]) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        } else {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }

        return cell;
        
    } wihtDidSelectRowAtIndexPath:^(UITableView *tableView, NSIndexPath *indexPath) {
        
        [selsceDic  setValue:dataArray[indexPath.row] forKey:@"APP_CHANGEVOICE"];
        [rootView tableviewReloadData];
        
//        ZYDateilViewController *vc =[ZYDateilViewController new];
//        [self.navigationController pushViewController:vc animated:YES];
        
        MyDatailViewController *vc =[[MyDatailViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
        
        
        
        NSDictionary *dic =  @{@"Action":@"GetErpProject",
                               @"sqlwhere":@"ID>0",
                               @"pagesize":@"10",
                               @"pageindex":@"1" // 第一页为1
                               };
        
        NSLog(@"-==%@",[dic toJsonString]);
        
        [[ZYNetWorking shared] postRequest:@"http://123.234.82.30/FlyERPApp/ErpProject.ashx" parameters:dic success:^(id responseObject) {
            NSLog(@"----%@",responseObject);
        } failure:^(NSError *error) {
            NSLog(@"--=====-%@",error);
            
        }];
        
        
        
    } withHeightForRowAtIndexPath:^CGFloat(UITableView *tableView, NSIndexPath *indexPath) {
        return 50;
    }];
    
    [rootView tableviewReloadDataWithData:dataArray];
    
    [rootView zyAddTableViewFooterView:^(NSInteger page) {
        
        [rootView zyFooterEndRefreshing];
        NSLog(@"-------%ld",page);
    }];
    
    [rootView zyAddTableViewHeaderView:^(NSInteger page) {
        [rootView zyHeaderEndRefreshing];
        NSLog(@"-------%ld",page);
    }];

    
    NSDate * today = [NSDate dateWithTimeIntervalSinceNow:-(3600 * 8)];
//    NSDate * today = [NSDate date];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
//    NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"GMT"];
    NSInteger interval = [zone secondsFromGMTForDate:today];
    NSDate *localeDate = [today dateByAddingTimeInterval:interval];
    NSLog(@"格林威治时间：%@", localeDate);
    NSString *timeSp = [NSString stringWithFormat:@"%ld",(long)[today timeIntervalSince1970]];
    NSLog(@"格林威治时间戳 : %@", timeSp);
        
//    [self showEmptyView:rootView WithImage:[UIImage imageNamed:@"icon-discover-press@3x"] andText:@"数据加载出现错误数据加载出现错误数据加载出现错误数据加载出现错误" subText:nil addEmptyRefresh:^{
//        NSLog(@"----重新加载数据");
//    }];
    
//        [MagicalRecord saveWithBlock:^(NSManagedObjectContext * _Nonnull localContext) {
//            NSLog(@"--------%@",localContext);
//            CSUser * cu = [CSUser MR_createEntityInContext:localContext];
//            cu.name = @"张三";
//            cu.age = @11;
//        }];
    
    
    NSString *pwdKey = @"ffff";
    NSString *password = @"duxinfeng123456duxinfeng123456duxinfeng123456";
    NSString *encryptedPWD = [AESCrypt encrypt:password password:pwdKey];
    NSString *decryptedPWD = [AESCrypt decrypt:encryptedPWD password:pwdKey];
    NSLog(@"加密后密码:%@ \n 解密后密码: %@",encryptedPWD,decryptedPWD);
    NSString *encryptedPWD1 = [UniversalEngine encryptAESData:password app_key:pwdKey];
    NSLog(@"加密后密码:%@ ",encryptedPWD1);
    
    
}


-(void)showListView
{
    NSArray *array = @[@"aaa",@"ccc"];
    ZYChoiceView *zyView = [ZYChoiceView shareChoiceView];
    zyView.titleString = @"请选择性别";
    zyView.itemString = @"确定";
    [zyView zyCellTitle:^NSString *(NSIndexPath *indexPath) {
        return array[indexPath.row];
    } andCellCount:^NSInteger{
        return array.count;// 显示几行cell
    } andAction:^(NSIndexPath *indexPath) {
                [zyView dismiss]; // 点击消失
        [self yuyinhecheng];
        
        ZYMainViewController *vc =[ZYMainViewController new];
        [self.navigationController pushViewController:vc
                                             animated:YES];
        
    }];
    [zyView show]; // 出现的方法
}
-(void)yuyinhecheng
{
    self.synthesizer = [[AVSpeechSynthesizer alloc] init];
    
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"iOS7新特性"];
    //设置语言类别（不能被识别，返回值为nil）
    AVSpeechSynthesisVoice *voiceType = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
    utterance.voice = voiceType;
    //设置语速快慢
    utterance.rate = 0.5;                     //最小为0.0，最大为1.0
    utterance.pitchMultiplier = 1;       //0.5-2.0之间
    utterance.volume = 0.75;             //0.0-1.0之间
    //语音合成器会生成音频
    [self.synthesizer speakUtterance:utterance];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
